package com.mjw.tender.service;

import com.mjw.tender.api.BlogUserService;
import com.mjw.tender.domain.BlogUser;
import com.mjw.tender.mapper.BlogUserMapper;
import org.apache.dubbo.config.annotation.Service;
import tk.mybatis.mapper.entity.Example;
import javax.annotation.Resource;
import java.util.List;

@Service(version = "1.0.0")
public class BlogUserServiceImpl implements BlogUserService {

    @Resource
    BlogUserMapper blogUserMapper;

    @Override
    public BlogUser get(Long tbUserId) {
        Example example = new Example(BlogUser.class);
        example.createCriteria().andEqualTo("tbUserId",tbUserId);
        return blogUserMapper.selectOneByExample(example);
    }

    public int modify(BlogUser blogUser){
        return blogUserMapper.updateByPrimaryKeySelective(blogUser);
    }

    @Override
    public BlogUser getByNickname(String nickname) {
        Example example = new Example(BlogUser.class);
        example.createCriteria().andEqualTo("nickname",nickname);
        BlogUser blogUser = blogUserMapper.selectOneByExample(example);
        return blogUser;
    }

    @Override
    public BlogUser getByUserName(String username) {
        Example example = new Example(BlogUser.class);
        example.createCriteria().andEqualTo("username",username);
        BlogUser blogUser = blogUserMapper.selectOneByExample(example);
        return blogUser;
    }

    @Override
    public List<BlogUser> getByShareFlag(boolean shareFlag) {
        Example example = new Example(BlogUser.class);
        example.createCriteria().andEqualTo("isshare",shareFlag);
        return blogUserMapper.selectByExample(example);
    }

    @Override
    public int add(BlogUser blogUser) {
        return blogUserMapper.insert(blogUser);
    }


}
